# Maintainer: Lukas Fleischer <lfleischer@archlinux.org>
# Contributor: xduugu
# Contributor: nh2
# Contributor: Steven Davidovitz <steviedizzle ð gmail đ com>
# Contributor: Nick B <Shirakawasuna ð gmail đ com>
# Contributor: Christof Musik <christof ð senfdax đ de>
# Contributor: Stefan Rupp <archlinux ð stefanrupp đ de>
# Contributor: Ignas Anikevicius <anikevicius ð gmail đ com>

pkgname=tp_smapi
pkgver=0.44
pkgrel=18
pkgdesc="Modules for ThinkPad's SMAPI functionality"
url='https://github.com/evgeni/tp_smapi'
arch=(loong64 x86_64)
license=(GPL)
makedepends=(
  git
  linux-headers
)
_commit=6e80bb1752280bcd142d86ecd0739661bd0e8312  # master
source=("git+https://github.com/evgeni/tp_smapi#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd tp_smapi
  git describe --tags | sed 's/^tp-smapi\///;s/[^-]*-g/r&/;s/-/+/g'
}

build() {
  cd tp_smapi

  # https://bugs.archlinux.org/task/54975 (kernel has no _GLOBAL_OFFSET_TABLE_):
  # Clear EXTRA_CFLAGS since it defaults to injecting CFLAGS and -fno-plt breaks the modules

  make HDAPS=1 KVER="$(</usr/src/linux/version)" EXTRA_CFLAGS=
}

package() {
  depends=('linux')

  local extradir=/usr/lib/modules/$(</usr/src/linux/version)/extramodules
  cd tp_smapi

  find . -name "*.ko" -exec install -Dt "$pkgdir$extradir" {} +
  find "$pkgdir" -name "*.ko" -exec strip --strip-debug {} +
  find "$pkgdir" -name "*.ko" -exec xz {} +

  # load module on startup
  echo tp_smapi | install -Dm644 /dev/stdin "$pkgdir/usr/lib/modules-load.d/$pkgname.conf"
}

# vim:set sw=2 sts=-1 et:
